<template>
	<view class="wrap">
		<u-form :model="model" :rules="rules" ref="uForm">
			<u-form-item label-width="350"
				:label-position="labelPosition" label="下入井内油管长度(m)" prop="h1">
				<u-input :border="border" placeholder="请输入下入井内油管长度" v-model="model.h1" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350"
				:label-position="labelPosition" label="套管内径(m)" prop="R">
				<u-input :border="border" placeholder="请输入套管内径" v-model="model.R" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350"
				:label-position="labelPosition" label="管鞋至灰面长度(m)" prop="h2">
				<u-input :border="border" placeholder="请输入管鞋至灰面长度" v-model="model.h2" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350"
				:label-position="labelPosition" label="油管容积系数(m³/m)" prop="q">
				<u-input :border="border" placeholder="请输入油管容积系数" v-model="model.q" type="digit"></u-input>
			</u-form-item>
		</u-form>

		<u-button type="primary" @click="submit">计算</u-button>

		<view class="u-config-wrap">
			<view class="u-config-item">
				<view class="u-item-title">计算结果</view>
				<u-form-item style="font-size: 22px;" :leftIconStyle="{color: '#888', fontSize: '32rpx'}" label-width="300"
					:label-position="labelPosition" label="顶替液用量" prop="V">
					<span v-if="model.V"> {{model.V}} m³ </span>
				</u-form-item>
			</view>
			<view class="u-config-item">
				<view class="u-item-title">计算公式</view>
				<view class="u-item-desc">V = qh1 + πR²h2</view>
				<view class="u-item-desc">式中：V— 顶替液用量 m³；Q— 油管容积系数 m³/m；h1— 下入井内油管长度 m；R— 套管内径 m；h2— 管鞋至灰面长度 m</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model: {
					h1: '',
					R: '',
					h2: '',
					q: '',
					V: ''
				},
				rules: {
					h1: [{
						required: true,
						message: '请输入下入井内油管长度',
						trigger: 'blur'
					}],
					R: [{
						required: true,
						message: '请输入套管内径',
						trigger: 'blur'
					}],
					h2: [{
						required: true,
						message: '请输入管鞋至灰面长度',
						trigger: 'blur'
					}],
					q: [{
						required: true,
						message: '请输入油管容积系数',
						trigger: 'blur'
					}]
				},
				labelPosition: 'left',
				border: true,
				
			};
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						const h1 = parseFloat(this.model.h1);
						const R = parseFloat(this.model.R);
						const h2 = parseFloat(this.model.h2);
						const q = parseFloat(this.model.q);
						
						// V = qh1 + πR²h2
						const V = (q * h1 + Math.PI * Math.pow(R, 2) * h2).toFixed(2);
						this.model.V = V;
					}
				});
			}
		}
	};
</script>

<style scoped lang="scss">
	.wrap {
		padding: 30rpx;
	}

	.u-config-wrap {
		margin-top: 30rpx;
	}

	.u-config-title {
		padding: 20rpx;
		font-size: 32rpx;
		font-weight: bold;
	}

	.u-config-item {
		padding: 20rpx;
	}

	.u-item-title {
		font-size: 28rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}

	.u-item-desc {
		font-size: 24rpx;
		color: #666;
	}
</style>